<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class belanja extends Default_My_Model {

    public function __construct() {
        parent::__construct();
        $this->load->database();
    }

    public function getBelanjaCustomer($whr) {
        $query = "
            
select 
s.nama_customer,
    s.alamat_customer,
    s.telepon_customer,
count(dit.id_item) as jumlah_item,
sum(dit.harga_beli) as harga_beli, sum(dit.harga_jual) as harga_jual, sum(dit.harga_beli_dollar) as harga_beli_dollar, sum(dit.harga_jual_dollar) as harga_jual_dollar 
from data_invoice_to_cust_item dit join data_invoice_to_cust di on di.id_invoice = dit.id_invoice 
join data_po_from_customer po on po.id_po = di.id_po
join master_customer s on po.id_customer = s.id_customer
$whr
group by 1,2,3";
        $resultSet = $this->db->query($query);
        return $resultSet->result();
    }

    public function getBelanjaSupplier($whr) {
        $query = "
select    
    s.nama_supplier,
    s.alamat_supplier,
    s.telepon_supplier,
    count(dit.id_item) jumlah_item,
    sum(dit.harga_beli) as harga_beli,
    sum(dit.harga_jual) as harga_jual,
    sum(dit.harga_beli_dollar) as harga_beli_dollar,
    sum(dit.harga_jual_dollar) as harga_jual_dollar
from data_invoice_from_supplier di join data_invoice_from_supplier_item dit on di.id_invoice = dit.id_invoice
join master_supplier s on di.id_supplier = s.id_supplier
$whr
group by 1,2,3";
        $resultSet = $this->db->query($query);
        return $resultSet->result();
    }

}

?>